package com.cloud.edu.sys.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.edu.contants.UrlConstant;
import com.cloud.edu.sys.model.Dictionary;
import com.cloud.edu.sys.service.SysDicService;
import com.cloud.edu.utils.PageUtils;
import com.cloud.edu.utils.R;

/**
 * 字典管理
 * 
 * @author dehuisun
 * @date 2018-12-12
 */
@RestController
@RequestMapping(UrlConstant.WEB_ADMIN_URL+"/dic")
public class SysDicController extends AbstractController {
	
	@Autowired
	private SysDicService sysDicService;
	
	/**
	 * 所有配置列表
	 */
	@GetMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		PageUtils page = sysDicService.queryPage(params);
		return R.ok().put("page", page);
	}
	
	
	/**
	 * 配置信息
	 * @throws Exception 
	 */
	@GetMapping("/info/{id}")
	public R info(@PathVariable("id") String id) throws Exception{
		Dictionary dictionary=sysDicService.selectById(id);
		return R.ok().put("dic", dictionary);
	}
	
	/**
	 * 保存配置
	 */
//	@SysLog("保存配置")
	@PostMapping("/save")
	public R save(@RequestBody Dictionary dictionary){
		sysDicService.save(dictionary);
		return R.ok();
	}
	
	/**
	 * 修改配置
	 */
	@PostMapping("/update")
	public R update(@RequestBody Dictionary dictionary){
		
		sysDicService.update(dictionary);
		
		return R.ok();
	}
	
	/**
	 * 删除配置
	 */
	@PostMapping("/delete")
	public R delete(@RequestBody String[] ids){
		sysDicService.deleteBatch(ids);
		
		return R.ok();
	}
	
	/**
	 * 获取数据字典列表
	 * @throws Exception 
	 */
	@GetMapping("/getDiclist/{classCode}")
	public R list(@PathVariable("classCode") String classCode) throws Exception{
		Dictionary dictionary=new Dictionary();
		dictionary.setClassCode(classCode);
		List<Dictionary> list = sysDicService.getList(dictionary);
		return R.ok().put("list", list);
	}

}
